package com.industrial.system.api.factory;

import cn.hutool.core.lang.tree.Tree;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.system.api.domain.BizAccountMapping;
import com.industrial.system.api.domain.RegisterWhiteUserForm;
import com.industrial.system.api.domain.SysDept;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import com.industrial.common.core.domain.R;
import com.industrial.system.api.RemoteUserService;
import com.industrial.system.api.domain.SysUser;
import com.industrial.system.api.model.LoginUser;

import java.util.List;
import java.util.Map;

/**
 * 用户服务降级处理
 * 
 * @author ttql
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserService()
        {
            @Override
            public R<LoginUser> getUserInfo(String username, String source)
            {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> registerUserInfo(SysUser sysUser, String source)
            {
                return R.fail("注册用户失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysUser>> getCurrentUserNameExist(List<String> uscc) {
                return R.fail("查询失败:"+ throwable.getMessage());
            }

            /**
             * <p>
             * 查询所有的管理员用户
             * </p>
             *
             * @return 结果
             */
            @Override
            public R<List<SysUser>> selectAdminUserList() {
                return R.fail("查询管理员用户失败:" + throwable.getMessage());
            }

            @Override
            public R<SysUser> getUserInfoByUserId(String userId) {
                return R.fail("查询管理员用户失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysUser>> getAdminUserList() {
                return R.fail("查询管理员用户列表失败:" + throwable.getMessage());
            }

            @Override
            public R<SysUser> getAdminUserInfoByAppointUserId(String userId) {
                return R.fail("查询管理员用户列表失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult updateAdministorUser(SysUser sysUser) {
                return AjaxResult.warn("修改用户信息失败:",throwable.getMessage());
            }

            @Override
            public AjaxResult removeUserByUserId(String userIds) {
                return AjaxResult.warn("修改用户信息失败:",throwable.getMessage());
            }

            @Override
            public AjaxResult insertNewUser(SysUser user) {
                return AjaxResult.warn("用户新增失败:",throwable.getMessage());
            }

            @Override
            public R<Boolean> clearAdminUserInfo(SysUser sysUser) {
                return R.fail("重置管理员信息失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysUser>> batchUpdatetUser(List<SysUser> uscc) {
                return R.fail("更新失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysUser>> batchInsertUser(List<SysUser> uscc) {
                return R.fail("保存失败:" + throwable.getMessage());
            }

            /**
             * @param userIdList
             * @return
             */
            @Override
            public R<List<SysUser>> queryUserInfoByUserIds(List<String> userIdList) {
                return R.fail("查询用户失败:" + throwable.getMessage());
            }

            /**
             * @param userIds
             * @return
             */
            @Override
            public R<List<SysDept>> queryDeptName(List<String> userIds) {
                return R.fail("查询用户所在部门失败:" + throwable.getMessage());
            }

            /**
             * <p>
             * 通过传入的用户ID查询该用户所在部门下的所有用户
             * </p>
             *
             * @param userId 用户ID
             * @return
             */
            @Override
            public R<List<SysUser>> queryUserInDeptAllUser(String userId) {
                return R.fail("查询用户失败:" + throwable.getMessage());
            }

            /**
             * <p>
             * 注册白名单用户
             * </p>
             *
             * @param sysUser
             * @return
             */
            @Override
            public R<Boolean> registerWithUser(RegisterWhiteUserForm sysUser) {
                return R.fail("白名单用户注册失败:" + throwable.getMessage());
            }

            /**
             * 更新白名单用户角色为白名单企业角色
             *
             * @param sysUser
             * @return
             */
            @Override
            public R<Boolean> updateWhiteUserRole(SysUser sysUser) {
                return R.fail("更新白名单用户角色失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> insertUserRole(SysUser sysUser) {
                return R.fail("插入角色失败:" + throwable.getMessage());
            }

            /**
             * 通过用户ID查询部门ID和部门名称
             *
             * @param userIds
             * @return
             */
            @Override
            public R<Map<String, String>> queryDeptIdAndDeptNameByUserId(List<String> userIds) {
                return R.fail("查询部门信息:" + throwable.getMessage());
            }

            @Override
            public R<List<String>> queryAreaCodeByAreaName(String areaName) {
                return R.fail("查询区域信息:" + throwable.getMessage());
            }

            // ============ 山东省统一登陆认证 ============
            @Override
            public R<LoginUser> selectUserMappingInfoByZwfwuuid(Map<String, Object> userInfoMap) {
                return R.fail("查询省用户信息失败:" + throwable.getMessage());
            }

            @Override
            public R<Map<String, Object>> selectSuserToBizUser(String uuid, String username) {
                return R.fail("登陆失败:" + throwable.getMessage());
            }

            @Override
            public R<LoginUser> querySdtUserBingBizUserStatus(String sUserId) {
                return R.fail("登陆失败:" + throwable.getMessage());
            }

            @Override
            public R<LoginUser> sdtUserBindBizUser(BizAccountMapping sysUser) {
                return R.fail("登陆失败:" + throwable.getMessage());
            }
        };
    }
}
